﻿using System;
using MyWeb.Business;
using MyWeb.Common;

namespace MyWeb.Controls
{
    public partial class u_newGroup_Default : System.Web.UI.UserControl
    {
        private string _lang = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            _lang = Session["Lang"].ToString() != "" ? Session["Lang"].ToString() : "vi";
            if(!IsPostBack)
            {
                ShowNews();
            }
        }
        private void ShowNews()
        {
            var listgn = GroupNewsService.GroupNews_GetByTop("2", "Active = '1' and Lang = '"+ _lang +"'", "[Ord]");
            if (listgn.Count > 0)
            {
                var s = "";
                foreach (var g in listgn)
                {
                    s += "<div class=\"newGroup clearn\"><div class=\"box\">\n";

                    s += "<div class=\"NewGroupMenu\">";
                    s += "<ul><li><strong>"+ g.Name +"</strong></li></ul>";
                    s += "</div>\n";

                    s += "<div class=\"NewGroupDetail\">";

                    var list = NewsService.News_GetByTop("1", "Active = '1' and [Index] != '1' and GroupNewId = '"+ g.Id +"'", "[Date] desc");
                    if(list.Count > 0)
                    {
                        s += "<div class=\"NewTop1\"><div class=\"box\">";
                        foreach (var t in list)
                        {
                            var links = "/tin-tuc/" + t.Tag + "/" + t.Id + ".html";
                            s += "<a href=\"" + links + "\" title='" + t.Name + "'><img src='" + StringClass.ThumbImage(t.Image) + "' alt='" + t.Name + "' /></a>";
                            s += "<h2 class=\"TitleNew\"><a href=\"" + links + "\" title='" + t.Name + "' class=\"link\">" + t.Name + "</a></h2>";
                            s += "<p>" + StringClass.SubText(t.Content, 75) + "</p>";
                            s += "</div>";
                        }
                        s += "</div>";
                    }
                    var list2 = NewsService.News_GetByTop("5", "Active = '1' and [Index] != '1' and GroupNewId = '" + g.Id + "'", "[Date] desc");
                    if(list2.Count > 0)
                    {
                        s += "<div class=\"NewTop3\"><div class=\"box\"><ul>";
                        for (var i = 0; i < list2.Count; i++)
                        {
                            var t = list2[i];
                            var links = "/tin-tuc/" + t.Tag + "/" + t.Id + ".html";
                            if(i > 0)
                            {
                                s += "<li><a href=\"" + links + "\" title='" + t.Name + "'>" + t.Name + "</a></li>";
                            }
                        }
                        s += "<ul></div></div>";
                    }
                    s += "<div class=\"clearn\">\n</div></div></div></div>\n";
                }
                ltrnewgroup.Text = s;
            }
        }
    }
}